<!--
 * @Author: chenhuanhuan 2925102113@qq.com
 * @Date: 2024-08-26 14:57:33
 * @LastEditors: chenhuanhuan 2925102113@qq.com
 * @LastEditTime: 2024-09-23 11:37:04
 * @FilePath: \orderApp\packageOne\pages\personalInfo\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<route lang="json5" type="page">
{
  layout: "default",
  style: {
    navigationStyle: "custom",
    navigationBarTextStyle: "black",
  },
}
</route>

<template>
  <view class="">
    <cu-navbar title="营养建议"></cu-navbar>
    <view>
      <!-- 菜肴详情 -->
      <cu-card margin="24rpx" padding="10">
        <uv-collapse :border="true" :value="[0]">                             
          <uv-collapse-item title="当天就餐记录">
            <view class="collapse-item">
              <view
                class="disheToday"
                v-for="(item, index) in dishesList"
                :key="item.recipedtlId"
                :class="{ noBorderBottom: index + 1 == dishesList.length }"
              >
                <view
                  class="disheTodayItem"
                  style="padding: 24rpx"
                  @click="item.open = !item.open"
                >
                  <view class="disheTodayItem-icon">
                    <uv-icon
                      color="#FFFFFF"
                      :class="{ 'u-arrow-down-icon-active': item.open }"
                      class="u-arrow-down-icon"
                      name="arrow-down"
                      size="12"
                    ></uv-icon>
                  </view>
                  <view class="disheTodayItem-title">菜肴</view>
                  <view class="disheTodayItem-name">
                    {{ item.dishName || "未知菜肴" }}
                    <span style="color: red; margin-left: 4rpx" v-if="item.res == 2"
                      >( 禁忌 )</span
                    >
                    <span style="color: green; margin-left: 4rpx" v-if="item.res == 3"
                      >( 推荐 )</span
                    >
                  </view>
                </view>
                <view v-if="item.open">
                  <view class="disheTodayItem" style="margin-bottom: 24rpx">
                    <view class="disheTodayItem-icon" style="background: #ffffff"></view>
                    <view class="disheTodayItem-title">摄入量(g)</view>
                    <view class="disheTodayItem-name">{{ item.weight || "未知" }}</view>
                  </view>
                  <view class="disheTodayItem" style="margin-bottom: 24rpx">
                    <view class="disheTodayItem-icon" style="background: #ffffff"></view>
                    <view class="disheTodayItem-title">时间</view>
                    <view class="disheTodayItem-name">{{ item.eatDate || "未知" }}</view>
                  </view>
                </view>
              </view>
            </view>
          </uv-collapse-item>
        </uv-collapse>
      </cu-card>

      <cu-card
        margin="24rpx"
        padding="10"
        v-for="(chartDataItm, index) in chartList"
        :key="index"
      >
      {{chartDataItm}}
        <!-- 能量图表 -->
        <uv-collapse :value="[0,1,2,3]">
          <uv-collapse-item title="近七天能量摄入标准比对图">
            <view class="collapse-item" style="padding: 0 24rpx">
              <view
                class="colorbox"
                style="display: flex; align-items: center; padding: 24rpx 0"
              >
                <view
                  style="
                    background: #71ce58;
                    margin-right: 8rpx;
                    width: 26rpx;
                    height: 26rpx;
                  "
                ></view>
                <view style="margin-right: 48rpx">标准输入(kcal)</view>
                <view
                  style="
                    background: #69b5ff;
                    margin-right: 8rpx;
                    width: 26rpx;
                    height: 26rpx;
                  "
                ></view>
                <view>实际输入(kcal)</view>
              </view>
              <view class="charts-box" style="height: 495rpx; width: 100%">
                <qiun-data-charts
                  type="line"
                  :opts="opts"
                  :chartData="chartDataItm"
                  canvasId="finance_a"
                  :canvas2d="true"
                />
              </view>
            </view>
          </uv-collapse-item>
        </uv-collapse>
      </cu-card>

      <cu-card margin="24rpx" padding="10">
        <uv-collapse :border="true" :value="[0]">
          <uv-collapse-item title="膳食营养建议" >
					<view class="collapse-item yinyang-table"
						style="color: #333333;font-size: 30rpx;line-height: 42rpx;padding: 24rpx;">
						<text>
							{{ content }}
						</text>
					</view>
				</uv-collapse-item>
          </uv-collapse>
        </cu-card>
    </view>
  </view>
</template>

<script lang="ts" setup>
//
import {
  getRepastInfo,
  getDietAdvice,
  getIntakeCurve,
  getUserNutrition,
} from "@/service/business/login";
import { useUserStore } from "@/store";

const { top } = useUserStore().pinia_SafeVal;

const { user } = useUserStore().userInfo;
const chartOriginData = () => ({
  categories: [],
  series: [
    {
      name: "标准输入",
      data: [],
      color: "#71CE58",
    },
    {
      name: "实际输入",
      data: [],
      color: "#69B5FF",
    },
  ],
});

/**图表数据 */
let chartData = ref(chartOriginData());
let chartList = ref([]);

const opts = reactive({
  padding: [15, 15, 15, 0],
  legend: {
    show: false,
  },
});
const reqIntakeCurve = () => {
  for (let i = 0; i < 4; i++) {
    getIntakeCurve({
      userId: user.userId,
      sign: i,
    }).then((res) => {
      if (res.retCode == 2000) {
        console.log(res.data)
        let standard = [];
        let reality = [];
        let time = [];
        res.data.standard.forEach((item, index) => {
          time.push(item.time);
          standard.push(item.value);
          reality.push(res.data.reality[index].value);
        });
        chartData.value = {
          categories: time,
          series: [{ data: standard }, { data: reality }],
        };

        chartList.value.push(chartData.value);


        console.log(chartList.value,chartData.value)
        chartData.value = chartOriginData();
      }
    });
  }
};

// 建议内容
const content = ref("");
const reqDietAdvice = ()=>{
  getDietAdvice({ userId: user.userId,}).then(res=>{
    if (res.retCode == 2000) {
      content.value = res.data
    }
  })
}

const dishesList = ref([]);

const reqRepastInfo = () => {
  getRepastInfo({
    userId: user.userId,
    kitchenId: user.kitchenId,
  }).then((res) => {
    if (res.retCode == 2000) {
      dishesList.value = res.data.map((el) => {
        el.open = true;
        return el;
      });
    }
  });
};

onMounted(() => {
  reqRepastInfo();
  reqIntakeCurve();
  reqDietAdvice()
});
</script>

<style lang="scss" scoped>
.titleBottom {
  border-bottom: none !important;
}

.slot-title {
  height: 96rpx;
  width: 100%;
  border: none !important;
  display: flex;
  align-items: center;

  image {
    width: 48rpx;
    height: 48rpx;
    margin-right: 24rpx;
  }

  .title {
    font-size: 30rpx;
    font-weight: 400;
    color: #999999;
    margin-right: 110rpx;
  }

  .dishesName {
    font-size: 34rpx;
    font-weight: 400;
    color: #333333;
  }
}

.detailBox {
  height: 88rpx;
  display: flex;
  align-items: center;

  &-title {
    /*  #ifdef  MP-WEIXIN  */
    margin-left: 72rpx !important;
    /*  #endif  */
    /*  #ifdef  APP-PLUS  */
    margin-left: 96rpx !important;
    /*  #endif  */

    font-size: 30rpx !important;
    font-weight: 400 !important;
    color: #999999 !important;
    width: 170rpx !important;
  }

  &-value {
    font-size: 34rpx !important;
    font-weight: 400 !important;
    color: #333333 !important;
  }
}

.slot-title-border {
  height: 96rpx;
  width: 100%;
  display: flex;
  align-items: center;
  border-bottom: 1rpx solid #eeeeee !important;

  image {
    width: 48rpx;
    height: 48rpx;
    margin-right: 24rpx;
  }

  .title {
    font-size: 30rpx;
    font-weight: 400;
    color: #999999;
    margin-right: 110rpx;
  }

  .dishesName {
    font-size: 34rpx;
    font-weight: 400;
    color: #333333;
  }
}

.detailBox {
  height: 88rpx;
  display: flex;
  align-items: center;

  &-title {
    /*  #ifdef  MP-WEIXIN  */
    margin-left: 72rpx !important;
    /*  #endif  */
    /*  #ifdef  APP-PLUS  */
    margin-left: 96rpx !important;
    /*  #endif  */
    font-size: 30rpx !important;
    font-weight: 400 !important;
    color: #999999 !important;
    width: 170rpx !important;
  }

  &-value {
    font-size: 34rpx !important;
    font-weight: 400 !important;
    color: #333333 !important;
  }
}

.table-end {
  border: solid 1rpx #e4e7ed;

  &-title {
    font-size: 24rpx;
    color: #303133;
    font-weight: bold;
    background-color: #f5f6f8;
    height: 68rpx;
    line-height: 68rpx;
    display: flex;
    padding: 0 20rpx;
  }

  &-content {
    display: flex;
    font-size: 24rpx;
    color: #303133;
    background-color: #ffffff;
    height: 68rpx;
    line-height: 68rpx;
    border-bottom: solid 1rpx #e4e7ed;
    padding: 0 20rpx;
  }
}

.echarts {
  margin-top: 16rpx;
  width: 100%;
  height: 495rpx;
}

.active-table-select {
  color: #00754a;
  border-bottom: 2rpx solid #00754a;
  height: 45rpx;
  line-height: 45rpx;
  width: 28rpx;
  margin: 0 20rpx;
  font-size: 26rpx;
  text-align: center;
}

.normal-table-select {
  color: #303133;
  border-bottom: 2rpx solid #ffffff;
  height: 45rpx;
  line-height: 45rpx;
  width: 28rpx;
  margin: 0 20rpx;
  font-size: 26rpx;
  text-align: center;
}
.disheToday {
  border-bottom: 1rpx solid #d8d8d8;
}
.disheTodayItem {
  display: flex;
  align-items: center;
  padding: 0 24rpx;
  &-icon {
    width: 32rpx;
    height: 32rpx;
    border-radius: 50%;
    background-color: #00754a;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 30rpx;
  }
  &-title {
    width: 150rpx;
    height: 40rpx;
    font-size: 28rpx;
    font-weight: 400;
    line-height: 40rpx;
    color: #999999;
    margin-right: 50rpx;
  }
  &-name {
    flex: 1;
    height: 40rpx;
    line-height: 40rpx;
    font-size: 28rpx;
    font-weight: 400;
    color: #333333;
  }
}
.u-arrow-down-icon {
  transition: all 0.3s;
}

.u-arrow-down-icon-active {
  transform: rotate(180deg);
  transform-origin: center center;
}

.noBorderBottom {
  border-bottom: none;
}
</style>
